const path = require('path')
const {
	name
} = require('./package')
const config = require("./src/config/projectsConfig.ts");
// import config from "./projectsConfig";
let projectName = process.env.PROJECT_NAME;

function resolve (dir) {
	return path.join(__dirname, dir)
}

const port = 9001

module.exports = {
	...config[projectName],
	publicPath: "./", // vue-cli3.3+新版本使用
	outputDir: "dist/" + projectName + "/",
	//   outputDir: 'dist',
	assetsDir: 'static',
	filenameHashing: true,
	pages: {
		projectName: {
			entry: `src/applications/${projectName}/main.ts`,
			template: "public/index.html",
			filename: "index.html",
		},
		//  manage: {
		//   entry: "src/applications/dataManage/main.ts",
		//   template: "public/index.html",
		//   filename: "index.html",
		// },
		//   server: {
		//   entry: "src/applications/dataServer/main.ts",
		//   template: "public/index.html",
		//   filename: "index.html",
		// },
	},
	devServer: {
		hot: true,
		disableHostCheck: true,
		port,
		overlay: {
			warnings: false,
			errors: true
		},
		headers: {
			'Access-Control-Allow-Origin': '*'
		}
	},
	// 自定义webpack配置
	configureWebpack: {
		resolve: {
			alias: {
				'@': resolve('src'),
				'~': resolve('packages'),

			}
		},
		output: {
			// 把子应用打包成 umd 库格式
			library: `${name}-[name]`,
			libraryTarget: 'umd',
			jsonpFunction: `webpackJsonp_${name}`
		}
	},
	// css: {
	// 	loaderOptions: {
	// 		less: {
	// 			data: `@import "./src/styles/index.less";`
	// 		}
	// 	}
	// },
	pluginOptions: {
		"style-resources-loader": {
			preProcessor: "less",
			patterns: [path.resolve(__dirname, "./src/styles/index.less")] //指定全局变量的less文件
		}
	},
	lintOnSave: false,
	devServer: {
		overlay: {
			warning: false,
			errors: false
		}
	}

	//   chainWebpack: config => {
	//     const types = ['vue-modules', 'vue', 'normal-modules', 'normal']
	//     types.forEach(type => addStyleResource(config.module.rule('less').oneOf(type)))
	//   }
}

// function addStyleResource(rule) {
//   rule.use('style-resource')
//     .loader('style-resources-loader').options({
//       patterns: [
//         path.resolve(__dirname, '@/styles/index.less')
//       ]
//     })
// }